Cleaned up code into several classes.

Added new utilities.
Removed unused methods.