fixing js function