Working version. Code commented extensively