Applying fixes for Issue #4 (credit: @ahoying)