Fixed inverted logic and added more debug info.