* simplified the code while keeping same functionality * reduced the number of functions (from 4 to 2) * clang-formatted