Some refactoring to variables reading and writing