Moved to predefining some global variables

Also made the creation of the application use the global xCore object.
This will allow us to attach things to it before the app is created and
have them persist after it is created.
Moved socket to xCore object
Added XM.Dispatch to handle function dispatching
Throw real error instead of string