Fixing bug in connection and write/connection