added a compact implementation