Reformat and clean up code. Add test to check if an exception is thrown when the template has no parent but tries to access $_self.parent