Stability/integrity improvements

Implements fixes for issues #3, #4, and #2.
Yes, but how can I test this properly?