added better error logging and fixed a bug with invalid paths