Fix sudden termination problem, performance, and issue with Safari