Change if statement in sync function

Added a check on null and undefined at the beginning of the function
instead of wrapping the content in a if.