Made some more refactorings, reformatted code and optimized imports