refactored bad lag array code