Bug fixes and histogram implementation