cleans up some code,adds comments