Using Cartan subalgebras to calculate nilradicals and Levi subalgebras of Lie algebras