refactored the code -Added extra cases