New branch with complete code rewriting.