Refactor galleries controller