richardzg pull request

merged conflicts, resubmitting per yiran's request