Fix hardcoded width value for img. Also improve readability & force buffer

clear on segfaults for some print statements.