improved spec and implementation