using handles prevent crashing app

and if there is below 500 sampels it crashed too