automat + refactoring