Seemingly correct code but not actually