Fix bug for image and simplify code
Simplify preference code