cleaned up code a bit
added some documentation