Merge "Refactor and comment complicated if statements"