Refactored to tidy output and ease future development.