many changes to remove unused and unclear code