Refactorize & allow plug external use