fixed threads, added command pattern for undo functionality