Moved main code into main() function.