 		@send 'USER', @opts.nick, '0', '*', 'An irc5 user'
 
 	onData: (pdata) ->
-		@data += pdata
+		@data = @data.concat pdata
 		while @data.length > 0
 			cr = false
 			crlf = undefined
 			for d,i in @data
-				d = d.charCodeAt 0
 				if d == 0x0d
 					cr = true
 				else if cr and d == 0x0a

			if crlf?
				line = @data.slice(0, crlf-1)
				@data = @data.slice(crlf+1)
				console.log '<=', line.toString('utf8')
				@onCommand(parseCommand line)
			else
				break

	send: (args...) ->
		msg = makeCommand args...
		console.log('=>', msg[0...msg.length-2])
		@socket.write(msg)

	onCommand: (cmd) ->
		switch cmd.command

		@socket = new net.Socket
		@socket.on 'connect', => @onConnect()
		@socket.on 'data', (data) => @onData data
		@data = []

	connect: ->
		@socket.connect(@port, @server)
