closing off javascript functions to fix bug