Working solution for ass2, with comments