updated code based on modified suggestions from pull request