Added some defensive code