complete rewrite to be fully SysV compatible