Cleaned up and added documentation.