move initializations into main
close command closes connection only if it is established
separate frame.js into individual frames