minor bug fix and code cleanup