First part of the refactoring to introduce the paper object to the code.

Refactoring is not fully done, but it should be in a stable state.
Fixed some file permissions