fixed bugs exposed by tests