Refactoring and some image operation

Signed-off-by: Laentir Valetov <laex@bk.ru>