refactoring of carousel js