rewrote toggleFlag, and fixed the module exports