2 external screens+Integrated screen with NVIDIA optimus not displayed correctly

Hello,

Hardware info:

-Custom laptop
-Core I7 4940MQ
-Geforce GTX 870M
-Ubuntu 14.04
-2 external monitors (1440x900) (one HDMI and one Display port)
-1 integrated monitor (1900x1080)
-configuration: 1 ext display above the integrated and 1 ext display to the right of the integrated one.
-nvidia driver 340.29 (the latest 346 crashes my X server)+ Nvidia prime

I use my nvidia card for CUDA applications. I wanted to add two external monitors to my integrated one.
Works fine on windows 7.
Works fine on ubuntu 14.04 if i use the IGP
Doesn’t work at all if i switch to nvidia card. Nvidia settings sees only one big screen and it results in corrupted display.

I really need the Nvidia card for cuda usage. Can someone help me?