Make safer and return proper error code
Clean up