Reformatting the code and making more modular