Adapted routines from nwx