cleaned up some code and added more documentation