[WIP] Refactor gallery

Trying to make gallery code better