checks on undefined
refactoring