revert incase to ifelse because of type inference problem