Controlling Program Flow In Javascript