fixing bugs and code readability