null condition removed and code refactoring