fixed bugs cleaned code