Initial pass at the assignment. Functional but needs tweaking, polish, and some refactoring.