Improved debug messages, more null checks and whatnot