Improved main func