improved minimal example by adding function
fixed bug