Refactored code. Removed sessions. Improved message handling.