debugged few error conditions