Code cleanup and organization; remove duplication in captionitpage.php