Check return-value of ref_sys_read(), and only search through the buffer that has been read.
Minor formatting fixes.
Merge pull request #2 from clevcode/master

Check return-value of ref_sys_read(), only search through read buffer.