MSE functions rewritten + testing added