Code cleanup and fix for mainloop

* Mainloop now loops over `read line <&3`. The mainloop will now break
  when the connection dies (e.g. the bot is killed on the server). This
  closes #5.