changed the caption algorithim