Buffer struct and allocation.
Moved secondary code to tools files
End of buffer handler fonctions