changed the logic