Added some safety/ error reporting