more cleanups and errorhandling