Refactor image management code to separate class