Updated connected method to work properly