Message work

Some refactoring. fixed attaching items to the database