Simplified the checkMessages function on both client and server, tweaked the design.