tdme: some improvments, optimizations