Fixed rewriting relative paths to headers and added various patches