Improve guides js

* Stop using global variable
* Simplify code