some better logic