Refactored handshaking process, moved it to a separate file, implemented HTTP authentication