fixed bug, cleaned code