Improved main script