simplified. Removed some lines I do not understand