extracted a function from the code