source sort and cleanup