Z sorting implemented. Scary changes.