added 'remaining' script, minor refactoring'