A bunch of refactoring. I know I probably missed a few things and admin.js needs more comments, but it's a start.
Merge branch 'master' into issue-2