restructured, updatated coes to fix reset issue