Added test functionality and refactored states