Code cleanup, design improvements