renamed things, cleaned up coding style, added comments