Better error handling, better handling of some cases