cleaned up code and fixed Example for completeness