trying to merge rafa's code, fixing chrome bug