Fixed dodgy bug, modified matlab