Working solution to assignment 2