Many refactorings, added ctrol-c catcher to controller loops.