Improved error checking...ish