Refactored ngMatrix code to be more readable.