successfully moved out the logic