Initial version, major import from internal project

Big thanks to Ben and to Paul for their work on the initial version from the LMS project.