restructured and cleaned up