Add ani2d support, refactor code