first working templated version