Added undefined check