now with more logic