pass buffer len for better length control