Add schemas code, second attempt.

You are using unsafe operations and then protecting them with an if statement instead of using the safe alternatives.

I would also say that using map or the for abstraction also makes the code more readable since it more idiomatic for this use case.