refactored test to reuse some code and keep things DRY