This code should be moved to connection()