My conditional logic is all screwed up