Bugfix switched needle and haystack
Add transaction handling