Refactor and add flags
100x speedup and different neighbor averaging