Main functions finished