bug fix and tweak