Tidied up javascripts, nicer rule testing