fixed performance problem with invalid samples