moved message handling to separate function