Fixed the image duplication. Refactored some more code