Optimization of membrane unit for removing carbon dioxide from natural gas