working version reformatted and gallery.php rewritten