return error code after cleanup