Mainly made the code simpler and more pythonic