moved pixel conversion to outside if statement