Incorporating MarkFo's changes from Pull Request #7