added template + changes to logic