Added some rewrites for Gallery Intergration.

* Removed some extraneous code from init function.
* refactored the sort functions, to simplify.