Implement part of new template extraction algorithm