Bugfix autorelease pool

First commit is a bugfix, others are code improvements.