Functioning version with improved documentation.