Cleanup of unused and confusing code