Some fine-tuning to main script