Fix compilation errors with proper logic