Simplified some work, still need to work on templates.