Fixed simple bug and added detailed error logs.