changed findMaxInNeighborhood for a more butiful/compact/efficient way