at() out of range fix & test