changed the logic to be more elegant.