Fixed logic - now tests pass