modified the method according to terry