Refactoring and simplifying code after refactoring by @jlipps