Header injection refactored, fixes #3. Plus minor code cleaing