Refactor and optimise coding style for readability