Fixed event bugs and function wrapping in Safari browser