Adjusted lines to do less in one line
New (working) example using practically the same coding. Removing the if statement will produce the same error.