Not sure if it'll solve all issues, but at least it should reduce amount of errors. Also added missed patch from previous commit.