wrote out the logic