Templates implemented.

Still some known bugs to fix