Amendments to logic to ensure all tests pass