added validextensions and removed nested if