Cleaned up matlab code.