refactor to ensure cross browser compatability