Revision 2

General improvements, expansions, and refactoring.