Fixed JS errors and loop issue temporarily