improve readability of code

* coding style fixes
* some PHPStorm code inspection fixes
* few method extractions
* removed unused methods
* whitespace fixes

 all as part of our code cleanup strategy and to make code better readable.
In this case using variables is for me not only better readable but also better debuggable as you can directly set a breakpoint before going into the function for instance. Will reply to the others later, don't have much time right now