Better function detection