Added state saving and fixed range in firefox (using someone else's thing)