Some refactoring made by slawek