fork from libbingham at https://code.google.com/p/bingham/