"msg" & "error" variables fixed and improvement