initial design, sorting, code clean-up