Refactoring mainly of the get_phases() method to get rid of the copy&paste code parts and make it readable.