moved vars to global to avoid crashs