Logic error fixes