Completed functionality. Lots of refactoring.