Buffer serial data

Signed-off-by: Paul Brook <paul@nowt.org>
Optimize array iteration order

Signed-off-by: Paul Brook <paul@nowt.org>