Fixed picture refresh problem
Refactored code