Updated comments, enhanced sanitization

Improved sanitization for user inputs, added detailed comments to all
functions.