Added error checking for invalid resources