Removed unneeded loop and cleaned code