Refactored the getXXXMatrix code.

More clean now! :)