add test and improve main script