backed up histogram calculation codes