improve main script and test