Improved input validation and documentation