Cleaned up code. Added comments.