Code Refactored

Code has been refactored to improve readability