Refactored and cleaned up test