Refactor for flatter, cleaner code