refactor open(), handle erros
handle more errors