Removed N squared loop at every solve