Major refactoring of the code, combine image and video handling