bug fix and clean code