You might want to pace it a bit. Checking if terraform has happened every 1/30 fraction of second is a bit too often.
Also it makes sense to only run widget:GameFrame after you have recieved "terraform complete message":
function widget:UnitFinished(unitID, unitDefID, unitTeam)
if unitTeam==myTeamId then
if unitDefID==terraunit.id then
--hey it makes sense to start checking if height is indeed of what I expected (as it takes time for spring to update heightmap)
end
end
end
P.S. Damn it eats code formatting.
If changes I proposed today pass, the code is going to become even more simple.