Avoid open dialog function override, fixes #5

Also added a few things that may or may not help avoid memory leaks.