added code for 3 and 4, png writing code and actual images