extracted logic from Register template