Fixed bug caught by tests