JPEG support, better error handling and minor API changes