Refactoring, cleanup, cruft removal