Refactoring. Unstable version.