Starting simulator code refactoring. Merging all existing branches.