Boxes js refactored and bug fix