Code cleanup & fixed one bug