some work on the galleries function