move try/catch out of keysForTree(), fix #9

since I can't really test if this still works, it would be nice if you took a closer look at it. 

Fixes #9