cleaning up gallery code