Fixes #19, #20. Thanks @erzr!