cleaned code, fixed minor bugs