clean up code to DRY