Cleaned up logic and generation of bat file