finally a debugged faster version