Fixed template inheritance via includes. Implemented a loop detection for includes