declare grant function before we use it