bug fix and make code easier to read