Template Code for fast implementation