Added the main algorithm, method to mask matrix value not working,
matrix.setValue method is ambiguous;