Check if animationHandler is null before calling it

Some code change to improve readability