Inserted an if to prevent php warnings