Refactored friend functions; tweaked Doxygen settings.

Made Definition an inner class of System; moved friend functions into the same file as the class they are friendly with.