Move XCB connection to seperate function

The beginning to a code cleanup. Things are starting to get messy.