Added functions to open and close connection