Added almost finished version of the algorithm. Around 70% of usecases are found!