Improved code and documentation for sample18