Refactored the image reading parts of readscreen.c