First working version. Really slow. Expect memory footprints of the order of 850MB