rearranged, cleaned up