Moved code from test to main