updated code and example