Initial import of Joren's code.