another round of speedups

I templated a few functions to be able to switch between double and float.
The original data is still double but the computation after that is double.
I also merged some function and removed the storage of the map as we just want the max of it