changed self to local function variable