refactoring common JS