cleaned up some code a bit
Added more commenting