Removed '.cache' from all paths.
Moved HTML page for /dir/file.jpg to /dir/file
Added redirects for old locations
Extracted bulk of main handler into separate methods.
Tidied up whitespace and made various minor improvements/bugfixes.