Refactoring for repetitive code.

Made some small "refactorings" to reflect how code should be organized and how to avoid repetitive work.