Changed for FF19 compatibility and removed a few brutal hacks.