Refactor heatmap function and add features