final version with comments