Refactored connection.py to a class