script.js refactored and new Connection class (partly implemented)