prevent out-of-bounds exception with threading enabled.