Fix and remove unused import.
Rearrange parsing function.
Move image processing into a handler.