fix bugs of functions/speed, tests not finished yet