Removing assert statements and replacing with an if statement