Added JavaScript and fixed bugs