Added test coverage for issue #8 and replaced instances of code that repeat the same logic