added max' and min', plus the start of a major refactor