Improved documentation, style and code cleanup