make all this logic more sound