added some better handling