Refactor animation js