Fixed bugs, cleaned code