Fixed potential access denied issue. fixes #5 and #10