add javascript functions and fix example