simpllified code to illustrate problem more clearly