improved prioritize dates algorithm
minor refactoring to improve readability