main and home script functions reordered