refactor code and add basic image support