added some more logic