New version, with more code