Cleaned up variable handling in Template