updated fully working main