Tightened up the error check