Very very big refactoring. Added support of multiyear documents.