Remove unused function
Clean up code, make protocol handling nicer