Fix some var names, improve JS reliability