Code cleanups, handling errors a tiny bit better