work on x-ends, cleanup in main file