Improve es5 strict mode compatibility

In es5 strict mode "function" could only be top-level statements.