Refactor token image loading to use the same logic regardless of the type of token image loaded.

Also fix style issues and log previously silent errors.