implemented serveronnection and did small code reorgnization