OSL emission fixes

- Fix bug when using P in shaders with emission closures.
- Small refactors