Fixing 'this' scope problem