Removed two for loops, hardly optimized. Should be totally optimized. I think