Chess: code refactoring