Code for lab3 of coursera course.