Fixed code based on failing tests