Finished histogram analysis, fixed some bugs in it as well.