More debugging.Now it is a fully functional code.
Added option to define target location.Now uses a separate page to get chapter names which previously were just numbers.