Version that works nicely

change m into inverse to make code more readable and added comments