adding mysql support and refactoring states