refactored connection.js to use prototypes