fixed histogram function