TSA: optimized implementation, found some unrelated issues (and fixed them)

git-svn-id: https://ehi.svn.codeplex.com/svn@29397 555e8bc2-ad3d-4a22-a156-a42dcab9bd6f