Fixed bug as instructed in lecture notes