Moved code into main() functon