using some suggestions from @wch. closes #1 closes #2