refactor to improve readability and code coverage
move logmessage to set_name, reducing complexity