Changed the code based on Pull Request comments from Matt