Fixed NPE
(cherry picked from commit 4db3670)
Fixed MatchError
(cherry picked from commit 2020078)