Refactored the code, removed old commented out sections