Fix segfault on __name__ lookup returning NULL

This also properly decrements PyObjects that are returned as new
references and refactors a bit to reduce the idention level.
Add a helper decorator for profiling a function