bugfixing message handling + code clean