Problem 2.13, also fixed several miscellaneous bugs