Move DG functions to an object, add enter key detection