Make it friendly to matlab, sacraficing some efficiency