added some more code that was discussed in Q&A