70% working main function