updated sorting to be more robust and cleaned up some stuff in languages