Improments to main script