convert to prototype-free style and refactor
add tests for all buffer types