Code cleanup/refactor