Bug fix and cleaned code