cleaned up functions. added main()