Fix variable reference in javascript