Move buf stuff into its own class