Patch 1

Several warning and notices in my error.log; Made more robust code.