Rafactoring the tempbox code