Missing headers and more bug fixes