Fixed some bugs in the printImage method