refractored JS into separate file, some style changes, modified copy