Completed Problem 17, added some new functions