SAX algorithm improvements and bug fixes