Fixed bug in testing loop