Bug fixes and cleanup of tpsm