Added empty() checks to stop PHP from outputting warnings