Added a bit better error checking in init.