fixed bug with wrong scope variable being used