Fixed JPEG encoder quality. Cleaned up code.