fix swapped variables, add error messages