Reimplementation of decpwd