Some Refactorings

Made a few refactorings to help make the code cleaner (see commit messages). :D