Refactor code; make use of batch