Better initialization, removed unnecessary static variables, reduced scopes where feasible