Tightened up code, added generic load_image() method

Tightened up the code, replaced several methods with a single generic load_image() and save_image() function. Will do the same for layer 0 and layer 1 encoding so we have good separation of concerns.