Refactored Code and Test