Add reference counting to not delete images in use