added some error hadling