updated code to work with more examples