Smart code is the most likely one to cause issues. When you try to detect something based on various factors, most likely there is an edge-case you haven't considered.
And when you can keep it simpler, keep it simpler. It'll make your life and especially debugging, easier, when the code is not smarter than you
@sheogorath As a legendary programmer wrote, “Exploit the limitations of your problem.” You rarely need to solve the general problem. Overly general code always leads to strange stuff in the actual application. I think this relates to what you wrote above.
This is my personal microblog. It's filled with my fun, joy and silliness.