implement get_substring as safe code