code refactoring for automation attempt