major restructuring, code will NOT compile. editing for simplicity, efficiency, and readability