originally based on the public domain implementation