Updated caption handling to address length bug