Improved order and checks of script