changed and cleaned code