converted old code more into instance form