a better implimentation of #113