Fixed crashes when running tests