Fix missing variables and possible PHP notices