ch6: add exit flag testing to frequencies