moved the code into a local function