Thomas is applying to refinance his mortgage. His first mortgage is $25,000 at a 9% rate. He plans to get cash out, up to $40,000. He qualifies for an 80% LTV and his house appraises for $100,000. Shortly before closing, the title exam shows $23,000 in mechanics liens. Closing costs total $6,000. How much cash will he receive at closing?