Added undo function - still a bit buggy but it's too late in the night to fix it right now