Made caption handling more generic