fixed a bug in selecting loops