added comments and cleaned up some superfluous code