Refactoring and improved test