Fixed bugs encountered in testing