fixes and better exception handling