Unwrapping the optional errorkey
Removed unneeded explicit type annotation
Made stuff immutable when appropriate
Removed unneeded logging statement