Refactors preview js