Changed return type to double array, swapped floats to doubles and fixed
mask loop