Better error handling
Various tweaks