Fix issue #1, 'Seperate out code in main'

Change-Id: Idc54ad1d940665a2d8e9898680155fd9f7943a4c