FIX: variable casting from mysql/postgres was causing 'remaining' value to be a string, causing the wrong logic to fire.