Updated to support TPA & minor optimizations