Added ThekliaLoop  smarty plugin, and reorganized code a bit