Fixing missing includes and rearranging variables declaratino