Fix missing headers
Lot of additions to logic