works but performance is worser than original python code, what went wrong ?