Finally solved the problem of levels in the lags. But window ifelse still not working.
lag solution fully implemented. still waiting on windows.