catch exceptions and fix some vars