Source sorting and optimizing