Rewrite almost from scratch. Many changes and refactorings. New features