added main menu. refactored some code