maximize / minimize code tidied