Refactoring + get rid of passing arguments by reference (because of troubles with testing the function via reflection)