This is all Max's code from f2p. Reusing it now.