Working version, compiles (but unstable)