error handling and tweaks