refactor code to use hash to substract from number