More code path test coverage

Added test coverage for untested code paths (mostly error handling) revealed by 'go tool cover'.
for i := range buf {

?