Updated documentation. Added comments. Cleaned up code.