improved main script