Cleaned up code. Add some docstrings. Updated version 2.5