refactor output; test code for buffer