bug fix and cleaned code