a bug fix and cleanup