Fixed casting, many improvements and fixes on the lua translation