cleaned up topology code