Reverting superfluous changes and refactoring some functions