BUGFIX Fixed memory leak in image io, performance improvements

Fixes #247