update images algorithm

+ refactoring style code