factor identical functions together