Major code cleanup, improved user interface