possible bug fix and cleaned code