restructure ash history buffer patch and make it a bit more secure