Fix javascript variables scope