Bug fixes and improvements in testing procedure