#2 Cleaned up and restructured code