This is all due to what is called the "order of precidence" - i.e., the order in which terms get evaluated.
if(!buffer == buffer2*)*
That doesn't do what you think it does. You are thinking it gives "If not (these two terms being equal)". Instead it gives "If (not this term) equal to that term".
The ! goes with the buffer and is calculated first before comparing it to buffer2*.*
Either use brackets to group things as they should be or use != to mean "not equal".