fix out of range errors in atom index