[RFC] Make the library faster and error-resilient

Comments and suggestions welcome.