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