length management added, polished the code, log files fixed