Major internal cleanup