save background index + refactor code