Improvements

-- some code restructuring part 1