Some refactoring done. Changed mode to control_mode and view_mode for different mode types.