Cleaned up code and some documentation