Fix js issues by localizing function