modified rotate sentence algorithm