Buggfixes, code cleanup. Only commenting left