Adds a proper error messages and fixes undefined keys