Factorize code.
Remove unused code.
Handle GIF.