Moved some image handling routines into the core module.
Fixed several egregious image cache related bugs.