Added on Enter Key functionality and refactored code