Add some defensive checks