improved code and examples