Updated for nested use

Updated JS to allow for nested control structure.