final version of javascript functions