cleaned code up, added more comments