Added some sanity to the code