Fixed various bugs and improved headers functionality