Adding some extra checks to prevent php warnings