Add histogram generation + fix some multithreading issues