move javascript to clarify structure