added comments and license, cleaned code up a bit