Added code to support gallery (incomplete)