added error logging and fixed syntax error