Cleaning up type conversions and error checking...