fixes #1 and also some cleaning up of serial.js