Several changes based on feedback on original pull request.