First almost working version, lot of TODOs and FIXMEs.