stable code, better error handling