Refactor scripts controller to be more readable