- refactorings and added null checks