much improved gallery function
version 1.3