Refactored an if-else, renamed a parameter to better describe its purpose and made minor formatting changes.