merged al's ipm code with matrix code