Improves the code style and removes globals/unused variables