Improves boundary handling of drag handler when in loop mode

Uses modulo to keep the stage within the boundaries when loop is
enabled. This also renames some variables and remove unused variables.