Refactored code for `def` command. It is far cleaner now