code refactoring

app still crahes on device