Added state handler state parameter and refactored module