(maint) Refactor Code

This commit refactors the code addressed in my pull request number 593.