converted to DRY-er solution