bug fix and clean up