Simplified code for Chrome. Reworked code for IE10.