rewrite backend in F#