move some functions out of block scope to avoid error in Firefox