Refactored and improved test