changed code, so its easier to understand