added improvements by @SteveDeFacto. closes #3