finished untested version of envAlgRes