Applied changes from #296 for better checking.