better implimentation of split