improved "onupgradeneeded" and error handling