added mouse_mode and refactored some code