object scope changed, function calling corrected, code optimized