Image refactoring (lib and tests)
Closes #2