Significant reworking of analysis_Hagerman and also some minor edits for testing purposes.