code duplication. move it to the separate function