Cleaned up and documented code.