Pull stuff out of main.lua

Change-Id: I901e6dc6b29d8a839d3c9faa2393eae8afd1bc9d