fixed holding counting - changed from err to res in checking statements