Moved functions to above main()