slightly better version with some error checks, root is taked from input
file