update Appendix B code