Added checks to get rid of php warnings