Clean up code for to_coo method.