Clean up ch.9 code