correct template based, but doesn't work well