Fixed a few bugs with the lua app state