Modularize mode and trim extraneous variables