Formatted and refactored small parts of the code