Basic implementation with several assumptions.  See implementation notes in readme.