bug fix and style cleanup