Improved Javascript - improved efficiency and now scaleable