refactor, add messages and db connection.