Fixed some more errors related to periodic images that gets repeated too much.
periodic/nonperiodic code is becoming a mess