Switches to PIL for image processing. Refactors code into separate files.