Updated implementation so it will work as expected with all values specified by W3C HTML5 spec.