cleaned up code according to suggestions in PR.