Change to ipairs, minor improvements to errors