Added more message logging
Fixed the state handling in message handlers
Added proper signal handling support