Small optimizations and exception improvements