Improve testing logic