Finished refactoring of header and also fixed bugs.