Remember to initialise buffer len to zero