Rewrote most of the CTF code