Fixed problem where cached images would not be written to cache directory on a device + did some minor clean up