added common functions from tern plugin