Added some important sanity checks and inits