Ran into a segfault and some memory leaks. Fixed them and added a decorator.

I tried not to change any behavior, but went ahead and refactored a little to reduce the indentation level while also handling the Py_DECREFs for the newly returned references.