Fixed JS Function and added init check