Fix error with JavaScript order of operations