final version, with comments