small code refactor to clean up some duplicate code and DRY it