Attempting to implement variable grid size for mode calculation.

Added a min function.

Need to fix the normalization function.