fix bugs reported by tests