Refactor some internal code

Hi, this refactor aims to improve code quality & make it more readable while reducing repetition.

I aim to keep committing but you're welcome to merge at any point and I can open new pull requests if you would like to keep the size of each change set down.

Please, let me know if there's anything you don't like in here.. I may have misunderstood the intention of any of the code.

You can see quality statistics for this over at [code climate](https://codeclimate.com/github/parndt/rails_admin).