Error handling and refactoring:
	*Error handling with pattern matching and case of.
	*Refactored the code with intrnal funcs and better naming.