Improved to ifelse statement