mex considered evil
adapted to tests
added tests