working algorithms, but timing fails