fix to mapping, some error check tweaks