Refactoring code of image beug