Moved code to allow app and tests to use same init code