separated prioritize/remove duplicate functions, added unit test