improved version, works on safari+mobile