Some reshuffling again and new function to convert the buffer
All the pieces are in place. Start debugging