[BUGFIX] Various code cleanup