cleanup, better error handling