some tweaks and exception handling