Cleaned up code and started adding documentation