Devin - refactored server code for listening for messages