Mako template code refactor

Mostly refactored some of our common/logical operations into functions in order to clean up the code a bit. This was also done to facilitate better API interaction as galaxy adds API functionality for IEs; we'll be able to remove the current functional call and replace with a call to galaxy's API.