Use sorted Map to simplify code