Many changes to make it simpler and more understandable