Fixes, code reogranization